package com.lmaye.design.patterns.behavioral.strategy;

import java.lang.reflect.Field;

/**
 * --
 *
 * @author lmay.Zhou
 * @date 2021/4/1 23:35
 * @qq 379839355
 * @email lmay@lmaye.com
 * @since JDK1.8
 */
public class Test {
    public static void main(String[] args) throws Exception {
        User user = new User(1L, "lmay", 10);
        Field[] fields = user.getClass().getDeclaredFields();
        for (Field it : fields) {
            String fieldName = it.getName();
            if("serialVersionUID".equals(fieldName)) {
                continue;
            }
            IType<?> type = StrategyFactory.getType(it.getType());
            // 私有属性必须设置访问权限
            it.setAccessible(true);
            String value = it.get(user).toString();
            Object o = type.conversionType(value);
            System.out.printf("Type: %s, Value: %s%n", o.getClass().getTypeName(), o);
        }
    }
}
